//
//  DJSearchBar.m
//  WeiboDemo
//
//  Created by Bworm on 15/1/30.
//  Copyright (c) 2015年 Bworm. All rights reserved.
//

#import "DJSearchBar.h"

@implementation DJSearchBar

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setup
{
    // 一次性的初始化
//    self.backgroundColor = [UIColor clearColor];
    self.background = [UIImage imageNamed:@"searchbar_background"];
    // 边框的样式 圆角
    self.borderStyle = UITextBorderStyleRoundedRect;
    // 搜索框提醒文本
    self.placeholder = @"大家都在搜: 张子萱闺蜜";
    // 搜索框左边的放大镜
    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"searchbar_searchlist_search_icon"]];
    self.leftView = image;
    self.leftViewMode = UITextFieldViewModeAlways;
    // 搜索框清除按钮
    self.clearButtonMode = UITextFieldViewModeAlways;
}

- (void)setLeftIconName:(NSString *)leftIconName
{
    _leftIconName = leftIconName;
    
    UIImageView *icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:leftIconName]];
    icon.width = 30;
    icon.contentMode = UIViewContentModeCenter;
    self.leftView = icon;
}

@end
